package edu.tces482.plms.logging;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;

public class LogFormatter extends Formatter {
	
	private static final String LINE_SEPERATOR = System.getProperty("line.separator");
	
	@Override
	public String format(LogRecord record) {
		StringBuilder sb = new StringBuilder();
		
		sb
//		.append(new Date(record.getMillis()))
//			.append(" ")
//			.append(record.getLoggerName())
//			.append(" ")
//			.append(record.getLevel().getLocalizedName())
//			.append(": ")
			.append(formatMessage(record))
			.append(LINE_SEPERATOR);
		
		if (record.getThrown() != null) {
			StringWriter sw = new StringWriter();
			PrintWriter pw = new PrintWriter(sw);
			record.getThrown().printStackTrace(pw);
			pw.close();
			sb.append(sw.toString());
		}
		
		return sb.toString();
	}

}
